<?php

class BidDao extends CFormModel
{

    protected $_bidMapper = array();

    public $customerId;
    public $auctionId;
    
    public function bidTypeMapper()
    {
        return array(
            'cash' => array(
                'class' => 'dao.bid.models.CashBidModel'
            ),
            'promo' => array(
                'class' => 'dao.bid.models.PromoBidModel'
            )
        );
    }
	
    public function getBid(){
    	$bidTypes=$this->bidTypeMapper();
    	$total=0;
    	foreach ($bidTypes as $type => $typeConfig){
    		$total+=$this->getBidModel($type)->getBid();
    	}
    	return $total;
    }
    
    public function getBidModel($type)
    {
        $bidTypeMapper = $this->bidTypeMapper();
        if (! array_key_exists($type, $this->_bidMapper)) {
            $className = Yii::import($bidTypeMapper[$type]['class']);
            $this->_bidMapper[$type] = new $className($this->getScenario());
        }
        $this->_bidMapper[$type]->customer_id = $this->customerId;
        $this->_bidMapper[$type]->auction_id = $this->auctionId;
        return $this->_bidMapper[$type];
    }
}